-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix certificate testing, and allowing RSA certs as well as pkcs12 #72
Conversation
@@ -258,7 +258,8 @@ public function submitForm(array &$form, FormStateInterface $formState): void { | |||
private function testCertificate(): void { | |||
try { | |||
$certificateLocator = $this->certificateLocatorHelper->getCertificateLocator(); | |||
$certificateLocator->getCertificates(); | |||
$certificate = $this->settings->getCertificate(); | |||
($certificate[CertificateLocatorHelper::LOCATOR_TYPE_FILE_SYSTEM]['path'] != NULL) ? $certificateLocator->getCertificate() : $certificateLocator->getCertificates(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the code need some commenting, it take a while to process these two lines.
When you're using condition, it is preferred to use if
structure, a shortened notation of a condition used when assigning the variable.
I don't think that the code servers the purpose now - before we checked of the cetificate can read by openssl_pkcs12_read
, however now the test will pass even when cerificate file is simply present in the system:
$certificateLocator->getCertificate()
is simply checking if there is a file with such name.
}, | ||
"zaporylie/composer-drupal-optimizations": "^1.2", | ||
"ext-openssl": "*" | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will you fix the formatting?
@@ -258,8 +258,27 @@ public function submitForm(array &$form, FormStateInterface $formState): void { | |||
private function testCertificate(): void { | |||
try { | |||
$certificateLocator = $this->certificateLocatorHelper->getCertificateLocator(); | |||
$certificateLocator->getCertificates(); | |||
$this->messenger()->addStatus($this->t('Certificate succesfully tested')); | |||
$certificatePath = $this->settings->getCertificate()[CertificateLocatorHelper::LOCATOR_TYPE_FILE_SYSTEM]['path']; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if the returned array is empty, you will get a warning here - because value is not set. Might be wise to handle that gracefully
// Check the private key against the certificate. | ||
$result = openssl_x509_check_private_key($certificateKeyFile, $keyCheckData); | ||
// If the result is not "1", throw an exception. | ||
if ($result != 1) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
returned result $result
is of type boolean. It would be more correct to compare it against boolean
value, instead of int
.
If fact syntax can be simplified to:
if ($result) {
...
…values Handled nested elements in webform inherit
@inuitviking and @stanbellcom, it seems weird that this PR is made from |
@rimi-itk i completely agree. I suggest to protected the develop and master branches from direct commits. |
@stanbellcom, I've set up branch protection on the |
No description provided.